package blackhouse_servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import blackhouse_server.change_teacherinfo_server;

import com.alibaba.fastjson.JSON;

@WebServlet("/change-teainfo")
public class change_teacherinfo_servlet extends HttpServlet
{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException
	{
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException
	{
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		String ID = (String) req.getSession().getAttribute("user");
		int tage = 0;
		String tgoodat = null;
		String tPhone = null;
		String tQQ = null;
		String temail = null;
		String taddress = null;
		change_teacherinfo_server cts = new change_teacherinfo_server();
		PrintWriter pw = resp.getWriter();
		if (!req.getParameter("tage").trim().equals(""))
		{
			tage = Integer.parseInt(req.getParameter("tage"));
			tgoodat = req.getParameter("tgoodat");
			tPhone = req.getParameter("tPhone");
			tQQ = req.getParameter("tQQ");
			temail = req.getParameter("temail");
			taddress = req.getParameter("taddress");
			boolean isok = cts.chanfetinfo(ID, tage, tgoodat, tPhone, tQQ,
					temail, taddress);
			pw.write(isok + "");
		} else
		{
			try
			{
				String json = JSON.toJSONString(cts.readytinfo(ID));
				pw.write(json);
			} catch (SQLException e)
			{

				e.printStackTrace();
			}
		}
	}
}
